﻿namespace _1.简单工厂模式;

/// <summary>
/// 运算类
/// </summary>
public class Operation
{
    public double NumberA { get; set; }
    public double NumberB { get; set; }
    //提供一个可重写具体运算的虚方法
    public virtual double GetResult()
    {
        double result = 0;
        return result;
    }
}

/// <summary>
/// 加法类
/// </summary>
class OperationAdd : Operation
{
    //重写父类的运算方法
    public override double GetResult()
    {
        double result = 0;
        result = NumberA + NumberB;
        return result;
    }
}

/// <summary>
/// 减法类
/// </summary>
class OperationSub : Operation
{
    public override double GetResult()
    {
        double result = 0;
        result = NumberA - NumberB;
        return result;
    }
}

/// <summary>
/// 乘法类
/// </summary>
class OperationMul : Operation
{
    public override double GetResult()
    {
        double result = 0;
        result = NumberA * NumberB;
        return result;
    }
}

/// <summary>
/// 除法类
/// </summary>
class OperationDiv : Operation
{
    public override double GetResult()
    {
        double result = 0;
        //如果除数为0应该抛出异常提示用户。
        if (NumberB == 0)
            throw new Exception("除数不能为0");
        result = NumberA / NumberB;
        return result;
    }
}
